<?php
/*
本系统由苏酷伊基于SiteHub项目二次开发
作者博客： https://www.sukuy.com/
后续更新地址： https://www.sukuy.com/navigation
作者QQ：3288637559
QQ交流群：884250547
任何第三方非官网在发布本系统时，不得删除该注释、版权信息、作者信息及官网等内容
*/
require('../includes/common.php');
if($_GET['act'] == 'detail' && defined('IN_ADMIN')) {
    $id = intval($_GET['id']);
    $feedback = $DB->find('52dh_site_feedback', '*', array('id' => $id));
    if($feedback) {
        echo json_encode(array('code' => 0, 'msg' => '获取成功', 'data' => $feedback));
    } else {
        echo json_encode(array('code' => -1, 'msg' => '记录不存在'));
    }
    exit;
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    exit(json_encode(array('code' => -1, 'msg' => '非法请求方式')));
}


session_start();
$site_id = _post('site_id');
$feedback_type = _post('feedback_type');
$feedback_desc = _post('feedback_desc');
$contact_info = _post('contact_info');
$captcha = _post('captcha');


if (empty($site_id) || empty($feedback_type) || empty($feedback_desc)) {
    exit(json_encode(array('code' => -1, 'msg' => '请填写完整信息')));
}


$site_info = $DB->find('52dh_site', '*', array('id' => $site_id));
if (empty($site_info)) {
    exit(json_encode(array('code' => -1, 'msg' => '无效的站点ID')));
}


$ip = getIp();
$hour_ago = time() - 3600;
$count = $DB->count('52dh_site_feedback', array('ip' => $ip, 'create_time >' => $hour_ago));
if ($count >= 3) {
    exit(json_encode(array('code' => -1, 'msg' => '提交过于频繁，请稍后再试')));
}


$data = array(
    'site_id' => $site_id,
    'site_name' => $site_info['name'],
    'site_url' => $site_info['url'],
    'feedback_type' => $feedback_type,
    'feedback_desc' => $feedback_desc,
    'contact_info' => $contact_info,
    'ip' => $ip,
    'user_agent' => $_SERVER['HTTP_USER_AGENT'],
    'status' => 0, 
    'create_time' => date('Y-m-d H:i:s')
);


$result = $DB->insert('52dh_site_feedback', $data);
if ($result) {
    
    $log = array(
        'type' => 'action',
        'username' => '访客',
        'action' => '提交站点异常反馈: ' . $site_info['name'],
        'ip' => $ip,
        'user_agent' => $_SERVER['HTTP_USER_AGENT'],
        'result' => 1
    );
    $DB->insert('log', $log);
    exit(json_encode(array('code' => 0, 'msg' => '反馈提交成功，感谢您的支持')));
} else {
    exit(json_encode(array('code' => -1, 'msg' => '反馈提交失败，请稍后重试')));
}
?>